from abc import ABC, abstractmethod
from typing import List, Optional

from app.schemas.certificates import Certificate
from app.schemas.dns import (
    DNSRecord,
    DNSRecordCreate,
    DNSRecordIdentifier,
    DNSRecordListRequest,
    DNSRecordUpdate,
    DomainSummary,
)


class BaseProvider(ABC):
    """云厂商适配器基类。"""

    def __init__(self, access_key: str, secret_key: str, region: str = "") -> None:
        self.access_key = access_key
        self.secret_key = secret_key
        self.region = region

    @abstractmethod
    def list_domains(self) -> List[DomainSummary]:
        """列出该账号下的所有域名。"""
        pass

    @abstractmethod
    def list_records(self, domain: str) -> List[DNSRecord]:
        """列出指定域名的所有解析记录。"""
        pass

    @abstractmethod
    def create_record(self, payload: DNSRecordCreate) -> DNSRecord:
        """创建解析记录。"""
        pass

    @abstractmethod
    def update_record(self, domain: str, payload: DNSRecordUpdate) -> DNSRecord:
        """更新解析记录。"""
        pass

    @abstractmethod
    def delete_record(self, domain: str, payload: DNSRecordIdentifier) -> None:
        """删除解析记录。"""
        pass

    @abstractmethod
    def batch_delete_records(self, domain: str, record_ids: List[str]) -> int:
        """批量删除解析记录。"""
        pass

    # ----- 证书相关接口 (可选实现) -----
    
    def apply_certificate(self, domains: List[str]) -> Certificate:
        """申请证书 (ACME 或云厂商托管)。"""
        raise NotImplementedError("Certificate application not implemented")

    def renew_certificate(self, cert_id: str) -> Certificate:
        """续签证书。"""
        raise NotImplementedError("Certificate renewal not implemented")
